/**
 * Created by Administrator on 2016/3/11.
 */
$(function () {
    //分页
    $('#fullpage').fullpage({
        afterLoad: function (anchorLink, index) {
            if (index == 2) {
                $('#page2').find('p, h1').delay(1500).addClass('enter');
            }
            if (index == 4) {
                $('#page4').find('p, h1').delay(1500).addClass('enter');
            }
        },

        onLeave: function (index, direction) {
            if (index == 2) {
                $('#page2').find('p, h1').delay(1500).removeClass('enter');
            }
            if (index == 4) {
                $('#page4').find('p, h1').delay(1500).removeClass('enter');
            }
        }

    });
    //swiper
    var swiper = new Swiper('.swiper-container', {
        loop: true,
        autoplay: 3000,
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 30
    });

    //计时器
    (function () {
        var count = 20;
        var speed = [];
        var curValue = [];
        var curCount = 0;
        $("#page1 .item .num").each(function (index, el) {
            speed[index] = parseFloat($(this).text()) / count;
            curValue[index] = 0;
        });
        var timer = setInterval(function () {
            curCount++;
            for (var i = 0; i < curValue.length; i++) {
                curValue[i] = curValue[i] + speed[i];
                $("#page1 .item .num").eq(i).text(parseFloat(curValue[i]).toFixed(2));
            }
            if (curCount == count) {
                clearInterval(timer);
            }
        }, 50);
    })();
    //背景图控件
    $('.background-image-holder').each(function () {
        var imgSrc = $(this).children('img').attr('src');
        $(this).css('background', 'url("' + imgSrc + '")');
        $(this).children('img').hide();
        $(this).css('background-position', '50% 0%');
    });

    //回到顶部
    $(".sprite-nav-back-to-top").click(function () {
        $.fn.fullpage.moveTo(1);
    });

    //var clientWidth = $('#page1').width();
    //var clientHeight = $('#page1').height();
    //var clientCenterX = clientWidth / 2;
    //var clientCenterY = clientHeight / 2;
    //console.log(clientCenterX);
    //console.log(clientCenterY);
    //if (SVG.supported) {
    //    var draw = SVG('atom');
    //    var rect = draw.circle(500).fill('#cefefe').opacity(".3").x(clientCenterX - 250).y(clientCenterY -250);
    //    var c1 = draw.ellipse(600, 200).fill('none').stroke('#fe5623').opacity(".3").rotate(0).cx(clientCenterX).cy(clientCenterY);
    //    var c2 = draw.ellipse(600, 200).fill('none').stroke('#fe5623').opacity(".3").rotate(0).cx(clientCenterX).cy(clientCenterY);
    //    var c3 = draw.ellipse(600, 200).fill('none').stroke('#fe5623').opacity(".3").rotate(0).cx(clientCenterX ).cy(clientCenterY);
    //} else {
    //    console.log('SVG not supported');
    //}
});